<?php

namespace Apps\AppApi\Method\User;


use Apps\AppApi\Method\BaseMethod;
use PhalconPlus\Api\Common\ResultStatus;
use Apps\Common\Models\BpFavorites;
use Apps\Common\Models\BeautyParlor;
use Apps\Common\Models\BeautyParlorTag;
use Apps\Common\Models\BuautyParlorTagInfo;
class FavoritesList extends BaseMethod
{
    public function run()
    {
    	if(false == $this->verifyUserAuth()){
    		return false;
    	}
    	
    	$page = $this->getDataItem('page', 1);
    	$limit = 10;
    	$offset = ($page-1) * $limit;
    	$userId = $this->getUserAuth()->userId;
    	if($userId==''){
    		return $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, '参数异常');
    	}
    	//$userId=1;
    	$my_favorites=BpFavorites::query()
    	->where("user_id = $userId")
    	->limit($limit, $offset)
    	->execute()->toArray();
    	foreach ($my_favorites as $fav){
    		$bp_list[]=BeautyParlor::findFirst([
    				"bp_id = ".$fav['bp_id'],
					"columns"=>['bp_id as id','bp_name as name','bp_cover as cover','bp_address as address']
					])
    				->toArray();
    	}
    	foreach ($bp_list as $k=>$v){
    		$bp_list[$k]['cover']="http://img.meelier.com/".$bp_list[$k]['cover'];
    		$tagarr=BeautyParlorTag::query()
    		->columns('i.tag_title')
    		->leftJoin('Apps\Common\Models\BeautyParlorTagInfo','Apps\Common\Models\BeautyParlorTag.tag_id = i.tag_id','i')
    		->where("Apps\Common\Models\BeautyParlorTag.bp_id = ".$bp_list[$k]['id'])
    		->orderby("Apps\Common\Models\BeautyParlorTag.sort asc")
    		->limit(3,0)
    		->execute()->toArray();
    		$newarr=[];
    		foreach ($tagarr as $key=>$val){
    			$newarr[]=$tagarr[$key]['tag_title'];
    		}
    		$bp_list[$k]['tags']=$newarr;
    	}
    	$this->setResult($bp_list);
    }


}